package cn.gailvlun.gll.util

import android.graphics.Rect
import android.support.annotation.Px
import android.support.v7.widget.RecyclerView
import android.view.View

class GridPaddingItemDecoration(val columns: Int, @Px val verticalSpace: Int, @Px val horizontalSpace: Int = verticalSpace): RecyclerView.ItemDecoration() {

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        super.getItemOffsets(outRect, view, parent, state)

        with(outRect) {
            top = if (columns > parent.getChildAdapterPosition(view)) 0 else verticalSpace
            left = if (parent.getChildAdapterPosition(view) % columns == 0) 0 else horizontalSpace
        }
    }

}